// pages/personal/private/private.js
var utils = require('../../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isfalse: true,
        isfalse1:true,
        isfalse2:true,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    //是否显示密码
    onloginyesTap: function (e) {
        var that = this;
        that.data.isfalse = !that.data.isfalse;
        that.setData({
            isfalse: that.data.isfalse
        })
    },
    onloginyesTap1: function (e) {
        var that = this;
        that.data.isfalse1 = !that.data.isfalse1;
        that.setData({
            isfalse1: that.data.isfalse1
        })
    },
    onloginyesTap2: function (e) {
        var that = this;
        that.data.isfalse2 = !that.data.isfalse2;
        that.setData({
            isfalse2: that.data.isfalse2
        })
    },
    formSubmit:function(e){
        var that = this;
        var oldpwd =e.detail.value.oldPwd;
        var newpwd = e.detail.value.newPwd;
        var confirmpwd =e.detail.value.confirmpwd;
        var pwd=wx.getStorageSync("login").password;
        console.log(wx.getStorageSync("login").password)
        if (oldpwd==pwd&&newpwd!=""&&newpwd==confirmpwd){
            utils.http(httpUrl + "/mobile/member/pwd_modify", {
            pwd: e.detail.value.oldPwd,
            new_pwd: e.detail.value.newPwd,
            confirm_pwd: e.detail.value.confirmpwd
        }, function (res) {
            if (res.state == 1) {
                utils.message("您已修改成功");
            } else {
                utils.message(res.datas);
            }
        })
        }else{
            if(oldpwd!=pwd){
                wx.showToast({
                    title: '原始密码错误',
                    image: "/images/error.png"
                })
            }else if(newpwd==""){
                wx.showToast({
                    title: '请输入新密码',
                    image: "/images/error.png"
                })
            } else if (newpwd != confirmpwd){
                wx.showToast({
                    title: '两次密码不一致',
                    image: "/images/error.png"
                })
            }
        }
       
    }
        
})